package com.tencent.wxcloudrun.controller.fangdong;

import com.tencent.wxcloudrun.config.ApiResponse;
import com.tencent.wxcloudrun.pojo.dto.resp.GetHeTongTenantResp;
import com.tencent.wxcloudrun.pojo.dto.resp.HistoryContractResp;
import com.tencent.wxcloudrun.service.business.fangdong.ContractService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;

@RestController
@RequestMapping("contract")
public class ContractController {

    @Resource
    private ContractService contractService;

    /**
     * 获取模板列表
     */
    @GetMapping("/getTmpList")
    public ApiResponse<String> getTmpList() {
        return new ApiResponse<>(contractService.getTmpList());
    }

    /**
     * 传递模板ID，然后换取文件下载临时URL，然后用 wx.downloadFile 方法把文件放到本地临时目录，然后用 wx.openDocument 方法进行预览
     */
    @GetMapping("/preview")
    public ApiResponse<String> preview(@NotBlank(message = "模板名不能为空") @RequestParam("tmpId") String tmpId) {
        return new ApiResponse<>(contractService.preview(tmpId));
    }

    /**
     * 点击【合同集】之后调用此接口
     */
    @GetMapping("/getHistoryContractList")
    public ApiResponse<List<HistoryContractResp>> getHistoryContractList() {
        return new ApiResponse<>(contractService.getHistoryContractList());
    }

    /**
     * 在合同集中获取具体合同的临时URL
     */
    @GetMapping("/getHeTongJiUrl")
    public ApiResponse<String> getHeTongJiUrl(@RequestParam("contractId") String contractId) {
        return new ApiResponse<>(contractService.getHeTongJiUrl(contractId));
    }

    /**
     * 在合同集中获取具体合同的临时URL
     */
    @GetMapping("/getHeTongTenant")
    public ApiResponse<List<GetHeTongTenantResp>> getHeTongTenant() {
        return new ApiResponse<>(contractService.getHeTongTenant());
    }
}
